package com.step.web;

import java.util.Arrays;
import java.util.List;

import com.alibaba.fastjson.JSON;

public class Leto {

	public static void main(String[] args) {
		compute("12345", "56", "1234567");
	}

	public static void compute(String red, String blue, String kj) {
		List<String> kjs = Arrays.asList(kj.split(""));
		// 先判断红球
		int rk = getNums(red,kjs,0,5);
		// 再判断蓝球
		int bk = getNums(blue,kjs,5,7);;
		// 判断几等奖
		zj(rk + "" + bk);
	}
	
	public static String compute(String red, String blue, List<String> kjs) {
		// 先判断红球
		int rk = getNums(red,kjs,0,5);
		// 再判断蓝球
		int bk = getNums(blue,kjs,5,7);;
		// 判断几等奖
		System.err.printf("rk:%s,bk:%s;\n red:%s;blue:%s;\n kjs:%s\n",rk,bk,red,blue,JSON.toJSONString(kjs));
		return zj(rk + "" + bk);
	}
	private static int getNums(String org, List<String> kjs, int start, int end) {
		int rel = 0;
		String[] orgs = org.split("#");
		for (String y : orgs) {
			for (int i = start; i < end; i++) {
				if (y.equals(kjs.get(i))) {
					rel++;
					break;
				}
			}
		}
		return rel;
	}

	// 中将规则
	private static String[] zjs = { "152", "251", "350", "442", "541", 
			"632", "740", "831", "822", "930", "921", "912","902" };

	private static String zj(String rb) {
		StringBuilder sd = new StringBuilder();
		for (String zj : zjs) {
			if (zj.lastIndexOf(rb) > 0) {
				sd.append(zj).append(",");
			}
		}
		if (sd.length() == 0) {
			return "未中奖!";
		}
		return sd.toString();
	}

}
